home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / cweb31p9d.lha / CWeb / wmerge.ch < prev    next >
Text File  |  1994-07-08  |  15KB  |  459 lines

  1.                                 -*-Web-*-
  2. This file, WMERGE.CH, is part of CWEB.
  3. It is a changefile for WMERGE.W, Version 3.1.
  4.  
  5. Authors and Contributors:
  6. (H2B) Hans-Hermann Bode, Universität Osnabrück,
  7.   (hhbode@@dosuni1.rz.uni-osnabrueck.de or HHBODE@@DOSUNI1.BITNET).
  8.  
  9. (KG) Klaus Guntermann, TH Darmstadt,
  10.   (guntermann@@iti.informatik.th-darmstadt.de).
  11.  
  12. (AS) Andreas Scherer,
  13.   Abt-Wolf-Straße 17, 96215 Lichtenfels, Germany.
  14.  
  15. Caveat utilitor:  Some of the source code introduced by this change file is
  16. made conditional to the use of specific compilers on specific systems.
  17. This applies to places marked with `#ifdef __TURBOC__' and `#ifdef _AMIGA'.
  18.  
  19. This program is distributed WITHOUT ANY WARRANTY, express or implied.
  20.  
  21. The following copyright notice extends to this changefile only, not to
  22. the masterfile WMERGE.W.
  23.  
  24. Copyright (C) 1993,1994 Andreas Scherer
  25. Copyright (C) 1991-1993 Hans-Hermann Bode
  26.  
  27. Permission is granted to make and distribute verbatim copies of this
  28. document provided that the copyright notice and this permission notice
  29. are preserved on all copies.
  30.  
  31. Permission is granted to copy and distribute modified versions of this
  32. document under the conditions for verbatim copying, provided that the
  33. entire resulting derived work is distributed under the terms of a
  34. permission notice identical to this one.
  35.  
  36. Version history:
  37.  
  38. Version    Date        Author    Comment
  39. p2    13 Feb 1992    H2B    First hack.
  40. p3    16 Apr 1992    H2B    Change of |@@i| allowed, /dev/null in case
  41.                 replaced by nul.
  42. p4    21 Jun 1992    H2B    Nothing changed.
  43. p5    21 Jul 1992    H2B    Nothing changed.
  44. p5a    30 Jul 1992    KG    remove one #include <stdio.h>,
  45.                 use strchr instead of index and
  46.                 include <string.h> for |strchr| declaration
  47. p5b    06 Aug 1992    KG    fixed a typo
  48. p6    06 Sep 1992    H2B    Nothing changed.
  49. p6a     15 Mar 1993     AS      SAS/C 6.0 support
  50. p6b     28 Jul 1993     AS      make some functions return `void'
  51. p6c    04 Sep 1993    AS    path searching with CWEBINCLUDE
  52. p7    09 Oct 1993    AS    Updated to CWEB 2.8
  53. p8a    11 Mar 1993    H2B    Converted to master change file.
  54.                 [Not released.]
  55. p8b    15 Apr 1993    H2B    Updated for wmerge.w 3.0beta (?).
  56.                 [Not released.]
  57. p8c    22 Jun 1993    H2B    Updated for final wmerge.w 3.0 (?).
  58. p8d    26 Oct 1993    AS    Incorporated with Amiga version 2.8 [p7].
  59. p8e    04 Nov 1993    AS    New patch level in accordance with CWEB.
  60. p9    18 Nov 1993    AS    Update for wmerge.w 3.1.
  61.     26 Nov 1993    AS    Minor casting problems fixed.
  62. p9c    18 Jan 1994    AS    Version information included.
  63. ------------------------------------------------------------------------------
  64. @x l.14
  65. #include <stdio.h>
  66. @y
  67. #include <stdio.h>
  68. #include <string.h>
  69. @z
  70. ------------------------------------------------------------------------------
  71. @x l.45
  72. @<Predecl...@>=
  73. extern int strlen(); /* length of string */
  74. extern char* strcpy(); /* copy one string to another */
  75. extern int strncmp(); /* compare up to $n$ string characters */
  76. extern char* strncpy(); /* copy up to $n$ string characters */
  77. @y
  78. @z
  79. ------------------------------------------------------------------------------
  80. @x l.94
  81. input_ln(fp) /* copies a line into |buffer| or returns 0 */
  82. FILE *fp; /* what file to read from */
  83. @y
  84. int input_ln(FILE *fp) /* copies a line into |buffer| or returns 0 */
  85.   /* |fp|: what file to read from */
  86. @z
  87. ------------------------------------------------------------------------------
  88. AmigaDOS allows path names with up to 255 characters.
  89. @x l.127
  90. @d max_file_name_length 60
  91. @y
  92. @d max_file_name_length 256
  93. @z
  94. ------------------------------------------------------------------------------
  95. The third argument of `strncpy' should be of type `size_t' not `long'.
  96. @x l.157
  97. @d lines_dont_match (change_limit-change_buffer != limit-buffer ||
  98.   strncmp(buffer, change_buffer, limit-buffer))
  99. @y
  100. @d lines_dont_match (change_limit-change_buffer != limit-buffer ||
  101.   strncmp(buffer, change_buffer, (size_t)(limit-buffer)))
  102. @z
  103. ------------------------------------------------------------------------------
  104. To avoid some nasty warnings by strict ANSI C compilers we redeclare all
  105. functions to `void' that return no concrete values.
  106. @x l.172
  107. void
  108. prime_the_change_buffer()
  109. @y
  110. void prime_the_change_buffer(void)
  111. @z
  112. ------------------------------------------------------------------------------
  113. The third argument of `strncpy' should be of type `size_t' not `long'.
  114. @x l.215
  115.   strncpy(change_buffer,buffer,limit-buffer+1);
  116. @y
  117.   strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
  118. @z
  119. ------------------------------------------------------------------------------
  120. Another `void' function, i.e., a procedure.
  121. @x l.231
  122. void
  123. check_change() /* switches to |change_file| if the buffers match */
  124. @y
  125. void check_change(void) /* switches to |change_file| if the buffers match */
  126. @z
  127. ------------------------------------------------------------------------------
  128. Another `void function, i.e., a procedure.
  129. @x l.283
  130. void
  131. reset_input()
  132. @y
  133. void reset_input(void)
  134. @z
  135. ------------------------------------------------------------------------------
  136. SAS/C defines `putchar' as a macro and reports a warning about multiple
  137. macro expansion.  The resulting `wmerge' is definitely wrong; it leaves
  138. every second letter out.
  139. @x l.345
  140. void put_line()
  141. {
  142.   char *ptr=buffer;
  143.   while (ptr<limit) putc(*ptr++,out_file);
  144.   putc('\n',out_file);
  145. }
  146. @y
  147. void put_line(void)
  148. {
  149.   char *ptr=buffer;
  150.   while (ptr<limit)
  151.   {
  152.     putc(*ptr,out_file);
  153.     *ptr++;
  154.   }
  155.   putc('\n',out_file);
  156. }
  157. @z
  158. ------------------------------------------------------------------------------
  159. @x l.352
  160. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  161. stop reading it and start reading from the named include file.  The
  162. \.{@@i} line should give a complete file name with or without
  163. double quotes.
  164. If the environment variable \.{CWEBINPUTS} is set, or if the compiler flag 
  165. of the same name was defined at compile time,
  166. \.{CWEB} will look for include files in the directory thus named, if
  167. it cannot find them in the current directory.
  168. (Colon-separated paths are not supported.)
  169. The remainder of the \.{@@i} line after the file name is ignored.
  170. @y
  171. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  172. stop reading it and start reading from the named include file.  The
  173. \.{@@i} line should give a complete file name with or without
  174. double quotes.  The remainder of the \.{@@i} line after the file name
  175. is ignored.  \.{CWEB} will look for include files in standard directories
  176. specified in the environment variable \.{CWEBINPUTS}. Multiple search paths
  177. can be specified by delimiting them with \.{PATH\_SEPARATOR}s.  The given
  178. file is searched for in the current directory first.  You also may include
  179. device names; these must have a \.{DEVICE\_SEPARATOR} as their rightmost
  180. character.
  181. @z
  182. ------------------------------------------------------------------------------
  183. CWEB will perform a path search for `@i'nclude files along the environment
  184. variable CWEBINPUTS in case the given file can not be opened in the current
  185. directory or in the absolute path.  The single paths are delimited by
  186. PATH_SEPARATORs.
  187. @x l.380
  188.   kk=getenv("CWEBINPUTS");
  189.   if (kk!=NULL) {
  190.     if ((l=strlen(kk))>max_file_name_length-2) too_long();
  191.     strcpy(temp_file_name,kk);
  192.   }
  193.   else {
  194. #ifdef CWEBINPUTS
  195.     if ((l=strlen(CWEBINPUTS))>max_file_name_length-2) too_long();
  196.     strcpy(temp_file_name,CWEBINPUTS);
  197. #else
  198.     l=0; 
  199. #endif /* |CWEBINPUTS| */
  200.   }
  201.   if (l>0) {
  202.     if (k+l+2>=cur_file_name_end)  too_long();
  203. @.Include file name ...@>
  204.     for (; k>= cur_file_name; k--) *(k+l+1)=*k;
  205.     strcpy(cur_file_name,temp_file_name);
  206.     cur_file_name[l]='/'; /* \UNIX/ pathname separator */
  207.     if ((cur_file=fopen(cur_file_name,"r"))!=NULL) {
  208.       cur_line=0; 
  209.       goto restart; /* success */
  210.     }
  211.   }
  212. @y
  213. @#
  214. #ifdef _AMIGA
  215. #define PATH_SEPARATOR   ','
  216. #define DIR_SEPARATOR    '/'
  217. #define DEVICE_SEPARATOR ':'
  218. #else
  219. #ifdef __TURBOC__
  220. #define PATH_SEPARATOR   ';'
  221. #define DIR_SEPARATOR    '\\'
  222. #define DEVICE_SEPARATOR ':'
  223. #else
  224. #define PATH_SEPARATOR   ':'
  225. #define DIR_SEPARATOR    '/'
  226. #define DEVICE_SEPARATOR '/'
  227. #endif
  228. #endif
  229. @#
  230.   if(0==set_path(include_path,getenv("CWEBINPUTS"))) {
  231.     include_depth--; goto restart; /* internal error */
  232.   }
  233.   path_prefix = include_path;
  234.   while(path_prefix) {
  235.     for(kk=temp_file_name, p=path_prefix, l=0;
  236.       p && *p && *p!=PATH_SEPARATOR;
  237.       *kk++ = *p++, l++);
  238.     if(path_prefix && *path_prefix && *path_prefix!=PATH_SEPARATOR &&
  239.       *--p!=DEVICE_SEPARATOR && *p!=DIR_SEPARATOR) {
  240.       *kk++ = DIR_SEPARATOR; l++;
  241.     }
  242.     if(k+l+2>=cur_file_name_end) too_long(); /* emergency break */
  243.     strcpy(kk,cur_file_name);
  244.     if(cur_file = fopen(temp_file_name,"r")) {
  245.       cur_line=0; goto restart; /* success */
  246.     }
  247.     if(next_path_prefix = strchr(path_prefix,PATH_SEPARATOR))
  248.       path_prefix = next_path_prefix+1;
  249.     else break; /* no more paths to search; no file found */
  250.   }
  251. @z
  252. ------------------------------------------------------------------------------
  253. Another `void' function, i.e., a procedure.
  254. @x l.450
  255. void
  256. check_complete(){
  257. @y
  258. void check_complete(void) {
  259. @z
  260. ------------------------------------------------------------------------------
  261. The third argument of `strncpy' should be of type `size_t' not `long'.
  262. @x l.453
  263.     strncpy(buffer,change_buffer,change_limit-change_buffer+1);
  264. @y
  265.     strncpy(buffer,change_buffer,(size_t)(change_limit-change_buffer+1));
  266. @z
  267. ------------------------------------------------------------------------------
  268. Another `void' function, i.e., a procedure.
  269. @x l.490
  270. @<Predecl...@>=
  271. void  err_print();
  272.  
  273. @
  274. @<Functions...@>=
  275. void
  276. err_print(s) /* prints `\..' and location of error message */
  277. char *s;
  278. @y
  279. @<Predecl...@>=
  280. void  err_print(char *);
  281.  
  282. @
  283. @<Functions...@>=
  284. void err_print(char *s) /* prints `\..' and location of error message */
  285. @z
  286. ------------------------------------------------------------------------------
  287. On the AMIGA it is very convenient to know a little bit more about the
  288. reasons why a program failed.  There are four levels of return for this
  289. purpose.  Let CWeb be so kind to use them, so scripts can be made better.
  290. @x l.540
  291. @ Some implementations may wish to pass the |history| value to the
  292. operating system so that it can be used to govern whether or not other
  293. programs are started. Here, for instance, we pass the operating system
  294. a status of 0 if and only if only harmless messages were printed.
  295. @^system dependencies@>
  296.  
  297. @<Func...@>=
  298. wrap_up() {
  299.   @<Print the job |history|@>;
  300.   if (history > harmless_message) return(1);
  301.   else return(0);
  302. }
  303. @y
  304. @ On multi-tasking systems like the Amiga it is very convenient to know
  305. a little bit more about the reasons why a program failed.  The four levels
  306. of return indicated by the |history| value are very suitable for this
  307. purpose.  Here, for instance, we pass the operating system a status of~0
  308. if and only if the run was a complete success.  Any warning or error
  309. message will result in a higher return value, so ARexx scripts can be
  310. made sensitive to these conditions.
  311. @^system dependencies@>
  312.  
  313. @d RETURN_OK     0 /* No problems, success */
  314. @d RETURN_WARN   5 /* A warning only */
  315. @d RETURN_ERROR 10 /* Something wrong */
  316. @d RETURN_FAIL  20 /* Complete or severe failure */
  317.  
  318. @<Func...@>=
  319. #ifndef __TURBOC__
  320. int wrap_up(void) {
  321.   @<Print the job |history|@>;
  322.   switch(history) {
  323.   case harmless_message: return(RETURN_WARN); break;
  324.   case error_message: return(RETURN_ERROR); break;
  325.   case fatal_message: return(RETURN_FAIL); break;
  326.   default: return(RETURN_OK);
  327.     }
  328. }
  329. #else
  330. int wrap_up(void) {
  331.   int return_val;
  332.  
  333.   @<Print the job |history|@>;
  334.   switch(history) {
  335.   case harmless_message: return_val=RETURN_WARN; break;
  336.   case error_message: return_val=RETURN_ERROR; break;
  337.   case fatal_message: return_val=RETURN_FAIL; break;
  338.   default: return_val=RETURN_OK;
  339.     }
  340.   return(return_val);
  341. }
  342. #endif
  343. @z
  344. ------------------------------------------------------------------------------
  345. @x l.569
  346. the names of those files. Most of the 128 flags are undefined but available
  347. @y
  348. the names of those files. Most of the 256 flags are undefined but available
  349. @z
  350. ------------------------------------------------------------------------------
  351. @x l.579
  352. boolean flags[128]; /* an option for each 7-bit code */
  353. @y
  354. boolean flags[256]; /* an option for each 8-bit code */
  355. @z
  356. ------------------------------------------------------------------------------
  357. @x l.593
  358. An omitted change file argument means that |'/dev/null'| should be used,
  359. @y
  360. An omitted change file argument means that |'/dev/null'| or---on {\mc
  361. MS-DOS} systems---|'nul'| or---on {\mc AMIGA} systems---|'NIL:'|
  362. should be used,
  363. @z
  364. ------------------------------------------------------------------------------
  365. Another `void' function, i.e., a procedure.
  366. @x l.599
  367. @<Pred...@>=
  368. void scan_args();
  369.  
  370. @
  371. @<Function...@>=
  372. void
  373. scan_args()
  374. @y
  375. @<Pred...@>=
  376. void scan_args(void);
  377.  
  378. @
  379. @<Function...@>=
  380. void scan_args(void)
  381. @z
  382. ------------------------------------------------------------------------------
  383. @x l.630
  384.   if (!found_change) strcpy(change_file_name,"/dev/null");
  385. @y
  386. #if defined( __TURBOC__ )
  387.   if (!found_change) strcpy(change_file_name,"nul");
  388. #elif defined( _AMIGA )
  389.   if (!found_change) strcpy(change_file_name,"NIL:");
  390. #else
  391.   if (!found_change) strcpy(change_file_name,"/dev/null");
  392. #endif
  393. @z
  394. ------------------------------------------------------------------------------
  395. @x l.612
  396. @* Index.
  397. @y
  398. @* Path searching.  By default, \.{CTANGLE} and \.{CWEAVE} are looking
  399. for include files along the path |CWEBINPUTS|.  By setting the environment
  400. variable of the same name to a different search path that suits your
  401. personal needs, you may override the default on startup.  The following
  402. procdure copies the value of the environment variable (if any) to the
  403. variable |include_path| used for path searching.
  404.  
  405. @<Functions@>=
  406. static boolean set_path(char *ptr,char *override)
  407. {
  408.   if(override) {
  409.     if(strlen(override) >= max_path_length) {
  410.       err_print("! Include path too long"); return(0);
  411. @.Include path too long@>
  412.     }
  413.     else strcpy(ptr, override);
  414.   }
  415.   return(1);
  416. }
  417.  
  418. @ The path search algorithm defined in section |@<Try to open...@>|
  419. needs a few extra variables.  The search path given in the environment
  420. variable |CWEBINPUTS| must not be longer than |max_path_length|.  If no
  421. string is given in this variable, the internal default |CWEBINPUTS| is
  422. used instead, which holds some sensible paths.
  423.  
  424. @d max_path_length 4095
  425.  
  426. @<Definitions...@>=
  427. char include_path[max_path_length+1]=CWEBINPUTS;@/
  428. char *p, *path_prefix, *next_path_prefix;@/
  429.  
  430. @ To satisfy all the {\mc ANSI} compilers out there, here are the
  431. prototypes of all internal functions.
  432.  
  433. @<Predecl...@>=
  434. int get_line(void);@/
  435. int input_ln(FILE *fp);@/
  436. int main(int argc,char **argv);
  437. int wrap_up(void);@/
  438. void check_change(void);@/
  439. void check_complete(void);@/
  440. void err_print(char *s);@/
  441. void prime_the_change_buffer(void);@/
  442. void put_line(void);@/
  443. void reset_input(void);@/
  444. void scan_args(void);@/
  445. static boolean set_path(char *ptr,char *override);@/
  446.  
  447. @ Version information.  The {\mc AMIGA} operating system provides the
  448. `version' command and good programs answer with some informations about
  449. their creation date and their current version.
  450.  
  451. @<Defi...@>=
  452. #ifdef _AMIGA
  453. const unsigned char *Version = "$VER: WMerge 3.1 [p9c] "__AMIGADATE__;
  454. #endif
  455.  
  456. @* Index.
  457. @z
  458. ------------------------------------------------------------------------------
  459.